import type { Directive, DirectiveBinding } from 'vue';
function eStop(e: any) {
    const _e: any = window.event || e;
    _e.preventDefault();
    _e.stopPropagation();
}
// 定义VUE3指令
const vFullscreen: Directive = {
    mounted(el: HTMLElement, binding: DirectiveBinding<any>) {
        // 鼠标按下
        function mouseDown(e: MouseEvent) {
            if (binding.value.type === 2) {
                eStop(e);
            }

            // fullscreen执行的Dom
            const fullscreenDom = document.getElementById(
                binding.value.dom as string
            ) as HTMLElement;

            // 给dom加class
            if (fullscreenDom) {
                if (fullscreenDom.classList.contains('as-fullscreen')) {
                    fullscreenDom.classList.remove('as-fullscreen');
                } else {
                    fullscreenDom.classList.add('as-fullscreen');
                }
            }
        }

        // fullscreen事件监听
        if (binding.value.type === 2) {
            el.addEventListener('dblclick', mouseDown);
        } else {
            el.addEventListener('click', mouseDown);
        }
    },
};

// 局部使用：
export default vFullscreen;

// 全局使用示例：
// const directives = {
//   install: function (app: any) {
//     app.directive('fullscreen', vFullscreen);
//   },
// };

// export default directives;
